<template>
  <div class="register-container">
    <!-- 页头 -->
    <index-header></index-header>
    <!-- 内容 -->
    <div class="title-container">
      <h3 class="title">
        {{ opeartionType }}
      </h3>
      <!-- <el-button class="login-btn" size="mini" type="text">
        <router-link to="/login">登录</router-link>
      </el-button> -->
    </div>
    <company-register-form v-show="companyRegisterFormShow"></company-register-form>
    <!-- 页脚 -->
    <index-footer></index-footer>
  </div>
</template>

<script>
import { validUsername, validPhone, validPassword, validVerifyCode, validGraphVerifyCode } from '@/utils/validate'
import GraphVerifyCode from '@/components/GraphVerifyCode'
import SocialSign from './components/SocialSignin'
import CompanyRegisterForm from './components/CompanyRegisterForm.vue'
import CompanySearchForm from './components/CompanySearchForm.vue'
import IndexHeader from '@/components/Header'
import IndexFooter from '@/components/Footer'

export default {
  name: 'Register',
  components: { GraphVerifyCode, SocialSign, CompanyRegisterForm, IndexHeader, IndexFooter },
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error('请输入正确的用户名称'))
      } else {
        callback()
      }
    }
    const validatePhone = (rule, value, callback) => {
      if (!validPhone(value)) {
        callback(new Error('请输入11位数的电话号码'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (!validPassword(value)) {
        callback(new Error('请输入8——16位的数字和字母的密码'))
      } else {
        callback()
      }
    }
    const validateVerifyCode = (rule, value, callback) => {
      if (!validVerifyCode(value)) {
        callback(new Error('请输入6位纯数字的验证码'))
      } else {
        callback()
      }
    }
    const validateGraphVerifyCode = (rule, value, callback) => {
      if (!validGraphVerifyCode(value)) {
        callback(new Error('请输入图形验证码只有4位'))
      } else {
        callback()
      }
    }
    return {
      opeartionType: '注册',
      companyRegisterFormShow: true,
      companyRegisterForm: {
        company_name: '',
        company_desc: '',
        company_address: '',
        administrator: '',
        phone: '',
        verify_code: '',
        graph_verify_code: ''
      },
      companyRegisterRules: {
        phone: [{ required: true, trigger: 'blur', validator: validatePhone }],
        verify_code: [{ required: true, trigger: 'blur', validator: validateVerifyCode }],
        graph_verify_code: [{ required: true, trigger: 'blur', validator: validateGraphVerifyCode }]
      },
      downCounterShow: '获取手机验证码',
      isVerifyCode: false,
      companyRegisterGraphVerifyCode: '',
      loginForm: {
        username: 'admin',
        password: '111111'
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      passwordType: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
      redirect: undefined,
      otherQuery: {}
    }
  },
  methods: {
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== 'redirect') {
          acc[cur] = query[cur]
        }
        return acc
      }, {})
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        const query = route.query
        if (query) {
          this.redirect = query.redirect
          this.otherQuery = this.getOtherQuery(query)
        }
      },
      immediate: true
    }
  },
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .register-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.register-container {
  .el-input {
    display: inline-block;
    // height: 47px;
    height: 30px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.register-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .title-container {
    position: relative;
    width: 520px;
    max-width: 100%;
    margin: 0 auto;
    overflow: hidden;

    .dropdown-container {
      color: #fff;
      position: absolute;
      top: 50px;
      font-size: 18px;
      // right: 0px;
      left: 0px;
      cursor: pointer;
    }

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 100px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
    .login-btn {
      color: #fff;
      position: absolute;
      top: 50px;
      font-size: 18px;
      right: 0px;
      cursor: pointer;
    }

    .set-language {
      color: #fff;
      position: absolute;
      top: 50px;
      font-size: 18px;
      right: 0px;
      cursor: pointer;
    }
  }


  .register-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    // padding: 100px 35px 0;
    padding: 10px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>
